package cn.tedu.property_management_system.controller;


import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.entity.VO.ParkingVO;
import cn.tedu.property_management_system.entity.dto.ParkingDAV;
import cn.tedu.property_management_system.entity.dto.ParkingDTO;
import cn.tedu.property_management_system.service.IParkingService;
import cn.tedu.property_management_system.utils.JsonPage;
import cn.tedu.property_management_system.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/parking")
public class ParkingController {
    @Autowired
    private IParkingService parkingService;

    @GetMapping("/select/get/by/{position}")
    public JsonResult<List<ParkingVO>> getByPosition(@PathVariable("position") String position) {
        log.debug("" + position);
        ParkingVO parkingVO = parkingService.getByPosition(position);
        List<ParkingVO> parkingVOS = new ArrayList<>();
        parkingVOS.add(parkingVO);
        return JsonResult.OK(parkingVOS);
    }

    @GetMapping("/select/parking")
    public JsonResult<List<ParkingVO>> selectParking() {
        log.debug("2-----");
        List<ParkingVO> parkingVOS = parkingService.getParking();
        log.debug(parkingVOS + "数据");
        return JsonResult.OK(parkingVOS);
    }

    @PostMapping("/insert/add/parking")
    public JsonResult<Integer> insertParking(@RequestBody ParkingDTO parkingDTO) {
        log.debug(parkingDTO + "---------");
        int row = parkingService.insertParking(parkingDTO);
        return JsonResult.OK(row);
    }

    @PostMapping("/update/by/id")
    public JsonResult<Integer> updateById(@RequestBody ParkingDAV parkingDAV) {
        log.debug(parkingDAV + "---修改-------");
        int row = parkingService.updateParking(parkingDAV);
        return JsonResult.OK(row);
    }

    @GetMapping("/delete/by/{id}")
    public JsonResult<Integer> deleteById(@PathVariable("id") Integer id) {
        log.debug(id + "------------");
        int row = parkingService.deleteParking(id);
        return JsonResult.OK(row);
    }

    @PostMapping("/delete/by/ids")
    public JsonResult<Void> deleteByIds(@RequestBody List<ParkingDAV> list) {
        log.debug(list + "----------");
        parkingService.deleteParkings(list);
        return JsonResult.OK();
    }


    @GetMapping("/select/get/position")
    public JsonResult<List<String>> getPositionById() {
        log.debug("7-------------");
        List<String> list = parkingService.getPosition();
        return JsonResult.OK(list);
    }

    @GetMapping("/select/by/{id}/parking")
    public JsonResult<ParkingVO> getParkingById(@PathVariable("id") Integer id) {
        log.debug(id + "-------------");
        ParkingVO parkingVO = parkingService.getById(id);
        return JsonResult.OK(parkingVO);
    }


    @GetMapping("/get/page/{pageSize}/{pageIndex}")
    public JsonPage<ParkingVO> getPage(@PathVariable("pageSize") Integer pageSize, @PathVariable("pageIndex") Integer pageIndex) {
        log.debug(pageSize+"-----"+pageIndex);
        JsonPage<ParkingVO> buildingJsonPage = parkingService.pageSelect(pageSize, pageIndex);
        return buildingJsonPage;
    }


}
